package com.bruce.springai.config;

import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.bruce.springai.repository.MongoChatMemoryRepository;

import jakarta.annotation.Resource;

/**
 * 聊天记忆配置
 */
@Configuration
public class ChatMemoryConfig {

    @Resource
    private MongoChatMemoryRepository mongoChatMemoryRepository ;


    /**
     * 持久化聊天记录
     * @return
     */
    @Bean
    public ChatMemory chatMemory(){

        return MessageWindowChatMemory.builder()
        .maxMessages(100)   // 最大记录数
        .chatMemoryRepository(mongoChatMemoryRepository) // 存储聊天记录的介质，默认是内存
        .build() ;
    }
}
